//
//  ZSVisitorView.swift
//  新浪微博-Swift
//
//  Created by 周李波 on 16/7/19.
//  Copyright © 2016年 q. All rights reserved.
//

import UIKit
import SnapKit

class ZSVisitorView: UIView {
    //定义闭包
    var closure:(()->())?
    
    
    //MARK:- 按钮点击事件
    func loginButtonClick(){
        //执行闭包
        closure!()
    }
    //MARK:- 外界判断是否为首页
    func setupVisitorViewInfo(imageName: String?,message: String?){
        if let imgName = imageName,let mes = message{
            iconImageView.image = UIImage(named: imgName)
            messageLabel.text = mes
            feedImageView.hidden = true
        }else{
            setupAnimation()
        }
        
    }
    
    
    //MARK:- 设置动画
    func setupAnimation(){
        let ca = CABasicAnimation(keyPath: "transform.rotation")
        ca.toValue = M_PI * 2
        ca.repeatCount = MAXFLOAT
        ca.duration = 10
        //防止动画停止
        ca.removedOnCompletion = false
        feedImageView.layer.addAnimation(ca, forKey: nil)
    }
    
    //MARK:- 初始化方法
    override init(frame: CGRect) {
        super.init(frame: frame)
        setupUI()
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    //MARK:- 设置UI
    func setupUI(){
        backgroundColor = UIColor(red: 237/255, green: 237/255, blue: 237/255, alpha: 1)
        //添加
        addSubview(feedImageView)
        addSubview(maskImageView)
        addSubview(iconImageView)
        addSubview(messageLabel)
        addSubview(loginButton)
        addSubview(regButton)
        //约束
        feedImageView.snp_makeConstraints { (make) in
            make.center.equalTo(self)
        }
        maskImageView.snp_makeConstraints { (make) in
            make.center.equalTo(self)
        }
        iconImageView.snp_makeConstraints { (make) in
            make.center.equalTo(self)
        }
        messageLabel.snp_makeConstraints { (make) in
            make.width.equalTo(230)
            make.height.equalTo(36)
            make.top.equalTo(maskImageView.snp_bottom).offset(16)
            make.centerX.equalTo(self)
        }
        loginButton.snp_makeConstraints { (make) in
            make.leading.equalTo(messageLabel)
            make.top.equalTo(messageLabel.snp_bottom).offset(16)
            make.width.equalTo(100)
            make.height.equalTo(36)
        }
        regButton.snp_makeConstraints { (make) in
            make.size.equalTo(loginButton)
            make.trailing.equalTo(messageLabel)
            make.top.equalTo(loginButton)
        }
        
        
    }
     
    //MARK:- 懒加载控件
    //圆圈
    private lazy var feedImageView:UIImageView = UIImageView(image: UIImage(named: "visitordiscover_feed_image_smallicon"))
    //遮罩
    private lazy var maskImageView:UIImageView = UIImageView(image: UIImage(named: "visitordiscover_feed_mask_smallicon"))
    //房子
    private lazy var iconImageView:UIImageView = UIImageView(image: UIImage(named: "visitordiscover_feed_image_house"))
    //文字
    private lazy var messageLabel:UILabel = {
    let label = UILabel()
        label.font = UIFont.systemFontOfSize(14)
        label.text = "关注一些人，回这里看看有什么惊喜关注一些人，回这里看看有什么惊喜"
        label.textColor = UIColor.grayColor()
        
        label.textAlignment = .Center
        label.numberOfLines = 0
        
        return label
    }()
    //登陆
    private lazy var loginButton:UIButton = {
       let button = UIButton()
        button.setTitle("登陆", forState: UIControlState.Normal)
        button.setTitleColor(UIColor.orangeColor(), forState: UIControlState.Normal)
        button.titleLabel?.font = UIFont.systemFontOfSize(15)
        button.setBackgroundImage(UIImage(named: "common_button_white_disable"), forState: UIControlState.Normal)
        button.addTarget(self, action: #selector(ZSVisitorView.loginButtonClick), forControlEvents: UIControlEvents.TouchUpInside)
        
        return button
    }()
    //注册
    private lazy var regButton:UIButton = {
        let button = UIButton()
        button.setTitle("注册", forState: UIControlState.Normal)
        button.setTitleColor(UIColor.orangeColor(), forState: UIControlState.Normal)
        button.titleLabel?.font = UIFont.systemFontOfSize(15)
        button.setBackgroundImage(UIImage(named: "common_button_white_disable"), forState: UIControlState.Normal)
        button.addTarget(self, action: #selector(ZSVisitorView.loginButtonClick), forControlEvents: UIControlEvents.TouchUpInside)
        
        return button
    }()

}
